package com.um.jdy.mp.report.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.mp.base.entity.vo.StationItemVO;
import com.um.jdy.mp.report.entity.vo.*;
import com.um.jdy.mp.report.enums.DateType;
import com.um.jdy.mp.report.enums.OrderBy;
import com.um.jdy.mp.report.service.DeviceDataService;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 设备统计
 *
 * @author cs
 * 日期 2023/5/23
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "设备统计")
@Validated
@RestController
@RequestMapping("/api/v1/device_data")
@SaCheckLogin
public class DeviceDataController {

    @Autowired
    DeviceDataService deviceDataService;

    @ApiOperation(value = "累计数据")
    @GetMapping("summary")
    public Response<DeviceSummaryVO> deviceDataManager() {
        return Response.success(deviceDataService.getDeviceSummary());
    }


    @ApiOperation(value = "设备使用率排名")
    @GetMapping("device_rate/page")
    public Response<Page<DeviceDataItemVO>> getDeviceRatePage(@ApiParam(value = "页码") @NotNull Integer page_no,
                                                              @ApiParam(value = "数据量") @NotNull Integer page_size,
                                                              @ApiParam(value = "时间") DateType data_type,
                                                              @ApiParam(value = "站场ID") String station_id,
                                                              @ApiParam(value = "排序") OrderBy order_by) {
        return Response.success(deviceDataService.getDeviceRatePage(page_no, page_size, data_type, station_id, order_by));
    }

    @ApiOperation(value = "站场设备使用率排名")
    @GetMapping("station_order/page")
    public Response<Page<StationDataItemVO>> getStationDeviceRatePage(@ApiParam(value = "页码") @NotNull Integer page_no,
                                                                      @ApiParam(value = "数据量") @NotNull Integer page_size,
                                                                      @ApiParam(value = "时间") DateType data_type,
                                                                      @ApiParam(value = "排序") OrderBy order_by) {
        return Response.success(deviceDataService.getStationDeviceRatePage(page_no, page_size, data_type, order_by));
    }


    @ApiOperation(value = "站场列表")
    @GetMapping("station/page")
    public Response<Page<StationItemVO>> getDeviceRatePage(@ApiParam(value = "页码") @NotNull Integer page_no,
                                                           @ApiParam(value = "数据量") @NotNull Integer page_size,
                                                           @ApiParam(value = "站场名称") String name) {
        return Response.success(deviceDataService.getStationPage(page_no, page_size, name));
    }


    @ApiOperation(value = "设备上下线统计")
    @GetMapping("device_offline/page")
    public Response<Page<DeviceStatusItemVO>> getDeviceOfflinePage(@ApiParam(value = "页码") @NotNull Integer page_no,
                                                                   @ApiParam(value = "数据量") @NotNull Integer page_size,
                                                                   @ApiParam(value = "时间") DateType data_type,
                                                                   @ApiParam(value = "站场ID") String station_id) {
        return Response.success(deviceDataService.getDeviceOfflinePage(page_no, page_size, data_type,station_id));
    }

    @ApiOperation(value = "未产生订单设备")
    @GetMapping("device_noorder/page")
    public Response<Page<DeviceDataItemVO>> getDeviceNoOrderPage(@ApiParam(value = "页码") @NotNull Integer page_no,
                                                                 @ApiParam(value = "数据量") @NotNull Integer page_size,
                                                                 @ApiParam(value = "时间") DateType data_type,
                                                                 @ApiParam(value = "站场ID") String station_id) {
        return Response.success(deviceDataService.getDeviceNoOrderPage(page_no, page_size, data_type,station_id));
    }

}
